import type { LanguageType } from '@/stores'

/**
 * @description 获取浏览器默认语言
 * @returns {string} 返回浏览器默认语言
 */
export function getBrowserLang(): LanguageType {
  const browserLang = navigator.language ? navigator.language : navigator.browserLanguage
  let defaultBrowserLang: LanguageType = 'zh'
  if (['cn', 'zh', 'zh-cn'].includes(browserLang.toLowerCase()))
    defaultBrowserLang = 'zh'
  else
    defaultBrowserLang = 'en'

  return defaultBrowserLang
}
export function initLanguage(): LanguageType {
  const globalStore = localStorage.getItem('store-global') || '{}'
  return JSON.parse(globalStore)?.language || getBrowserLang()
}
